package com.lanou.dllo.shise.com.lanou.dllo.activity;

import android.support.v7.app.AppCompatActivity;
import android.os.Bundle;
import android.view.MenuItem;
import android.view.View;
import android.widget.Button;
import android.widget.EditText;
import android.widget.PopupMenu;
import android.widget.Toast;

import com.lanou.dllo.shise.R;
import com.lanou.dllo.shise.com.lanou.dllo.application.SysApplication;

public class Feed_backActivity extends AppCompatActivity {
    private Button oldPopupMenu, sexPopupMenu, submitBtn;
    private EditText edit_query;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_feed_back);
        SysApplication.getInstance().addActivity(this);
        oldPopupMenu = (Button) findViewById(R.id.oldPopupMenu);
        sexPopupMenu = (Button) findViewById(R.id.sexPopupMenu);
        edit_query = (EditText) findViewById(R.id.edit);
        submitBtn = (Button) findViewById(R.id.submitBtn);
        submitBtn.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                if (edit_query != null && edit_query.length()<= 8){
                    Toast.makeText(Feed_backActivity.this,"请输入反馈内容",Toast.LENGTH_LONG).show();
                } else {
                    Toast.makeText(Feed_backActivity.this,"提交成功",Toast.LENGTH_LONG).show();
                }

            }
        });
        oldPopupMenu.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                showoldPopMenu(oldPopupMenu);

            }
        });
        sexPopupMenu.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                showsexPopupMenu(sexPopupMenu);
            }
        });
    }

    private void showsexPopupMenu(final Button sexPopupMenu) {
        PopupMenu ps = new PopupMenu(this,sexPopupMenu);
        ps.getMenuInflater().inflate(R.menu.sexmenu,ps.getMenu());
        ps.setOnMenuItemClickListener(new PopupMenu.OnMenuItemClickListener() {
            @Override
            public boolean onMenuItemClick(MenuItem item) {
                switch (item.getItemId()){
                    case R.id.sexItem:
                        sexPopupMenu.setText("性别");
                        break;
                    case R.id.manItem:
                        sexPopupMenu.setText("男");
                        break;
                    case R.id.womanItem:
                        sexPopupMenu.setText("女");
                        break;
                    default:
                        break;

                }
                return false;
            }
        });
        ps.show();
    }

    private void showoldPopMenu(View anchor) {
        PopupMenu pm = new PopupMenu(this, anchor);
        //加载菜单文件
        pm.getMenuInflater().inflate(R.menu.oldmenu,pm.getMenu());
        pm.setOnMenuItemClickListener(new PopupMenu.OnMenuItemClickListener() {
            @Override
            public boolean onMenuItemClick(MenuItem item) {
                switch (item.getItemId()) {
                    case R.id.oldItem:
                        oldPopupMenu.setText("年龄");
                    case R.id.eighthItem:
                        oldPopupMenu.setText("18岁以下");
                        break;
                    case R.id.twentyfourItem:
                        oldPopupMenu.setText("18-24岁");
                        break;
                    case R.id.thirtyItem:
                        oldPopupMenu.setText("25-30岁");
                        break;
                    case R.id.thirtyfifthItem:
                        oldPopupMenu.setText("31-35岁");
                        break;
                    case R.id.fourtyItem:
                        oldPopupMenu.setText("36-40岁");
                        break;
                    case R.id.fiftyItem:
                        oldPopupMenu.setText("41-50岁");
                        break;
                    case R.id.fiftynineItem:
                        oldPopupMenu.setText("51-59岁");
                        break;
                    case R.id.sixtyItem:
                        oldPopupMenu.setText("60岁及以上");
                        break;
                    default:
                        break;
                }
                return false;
            }
        });
        pm.show();

    }


}





